//
//  ManageTieZiModel.m
//  Lucky28
//
//  Created by zr on 2018/8/6.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "ManageTieZiModel.h"

@implementation ManageTieZiModel


+(instancetype)modelWithDictionary:(NSDictionary *)dic{
    
    ManageTieZiModel *model =[[ManageTieZiModel alloc] init];
    
    [model setValuesForKeysWithDictionary:dic];
    
    return model;
}


+(void)manageTieZiWithType:(NSString *)type WithSucess:(void (^)(NSArray<ManageTieZiModel *> *))sucessBlock error:(void (^)(void))errorBlock{
    
    NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
    
    NSString * user_id = [userDefaults objectForKey:@"user_id"];
    NSString * token = [userDefaults objectForKey:@"token"];
    
    NSDictionary * parameters;
    
    if ([type isEqualToString:@"0"]) {
        parameters = @{@"user_id":user_id,@"note_type":@"4",@"token":token};
    }else {
        parameters = @{@"user_id":user_id,@"note_type":@"4",@"type":type,@"token":token};
    }
    
    [[NetworkTool sharedTools] POST:@"/index/Note/noteList" parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *  _Nullable responseObject) {
        
//        NSLog(@"====%@",responseObject);
        NSString * msg = responseObject[@"msg"];
        
        if ([msg isEqualToString:@"无数据"]) {
            
            NSArray * array = nil;
            sucessBlock(array);
            
        }else{
            
            NSArray * paramArray = responseObject[@"data"];
            
//            NSLog(@"==%@",paramArray);
            
            NSMutableArray *mArray = [NSMutableArray array];
            
            [paramArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                
                ManageTieZiModel * model = [ManageTieZiModel modelWithDictionary:obj];
                
                [mArray addObject:model];
                
            }];
            
            if(sucessBlock){
                sucessBlock(mArray.copy);
            }
        }
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
    
}


- (void)setValue:(id)value forKey:(NSString *)key{
    
    if ([key isEqualToString:@"id"]) {
        
        self.ID = value;
    }else{
        
        [super setValue:value forKey:key];
    }
    
}


-(void)setValue:(id)value forUndefinedKey:(NSString *)key{
}

@end
